<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/print.css">
		<style>
			#star {
				color: red;
			}
		</style>
	</head>

	<body style="padding: 0px;">

		<div id="toolbar" style="background: #F4F4F4;border-top:1px solid #95B8E7">
		</div>
		<div>
			<div style="float: right;margin-top: 0px;max-width:60px;" id="notreview"></div>
			<form id="ff" method="post">
				<table style="text-align: left;width: 80%;margin: 0 auto;" cellpadding="5">
					<tr>
						<td width="20%">销售单号</td>
						<td width="30%"><input id="input_ORDER_NO" style="width: 100%;" class="easyui-textbox" name="ORDER_NO" data-options="disabled:true,required:true"></input>
						</td>
						<td width="20%">用户组</td>
						<td width="30%"><input id="input_CUSTOMER_TYPE" style="width: 100%;" class="easyui-textbox" name="CUSTOMER_TYPE" data-options="disabled:true,required:true"></input>
						</td>
					</tr>
					<tr>
						<td width="20%">配送单位</td>
						<td width="30%"><input id="input_CUSTOMER_NAME" style="width: 100%;" class="easyui-textbox" name="CUSTOMER_NAME" data-options="disabled:true,required:true"></input>
						</td>
						<td width="20%">配送时间</td>
						<td width="30%">
							<input id="input_DISTRIBUTION_DATE" style="width: 100%;" class="easyui-textbox" data-options="disabled:true" type="text" name="DISTRIBUTION_DATE"></input>
						</td>
					</tr>
				</table>

				<table id="tt">

				</table>
				<div style="padding: 10px 0px;">
					<table>
						<tr>
							<th>人民币金额合计</th>
							<td>
								<input type="text" class="print_text_style" name="number" />
							</td>
							<th>人民币金额合计(大写)</th>
							<td width="auto">
								<input type="text" class="print_text_style" id="dx" />
								<div id="dx"></div>
							</td>
						</tr>
					</table>
				</div>
				<div style="margin-left: 20%;" id="new_footer">

				</div>
			</form>
		</div>
		<div id="dlg" class="hiddenDialog">
			<iframe id="ifrmEdit" style="width: 100%;height: 100%;" frameborder="0" scrolling="no"></iframe>
		</div>
	</body>
	<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
	<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../../JS/common.js"></script>
	<script type="text/javascript" src="../../../JS/finance.js"></script>
	<script type="text/javascript" src="../../../JS/jquery.edatagrid.js"></script>
	<script type="text/javascript" src="../../../JS/SHA-1.js"></script>
	<script type="text/javascript">
		var currPageData;//保存当前页面信息；
		var id = getID();
		var originalid;//打印原始订单的ID
		var customerid;
		var MaxPage = 0;
		var MinPage = 1;
		var _Modi_Des = "";
		var currid = AddFlag; //当前页面的ID
		var auth = "admin;" + hex_sha1("admin1");
		
		///增加脚注
		addFooter($("#new_footer"));
		//增加单据的toolbar
		var tooldata = [{
			"icon": "icon-print",
			"func": "print('A')",
			"functionname": "打印原始销售单"
		}, {
			"icon": "icon-print",
			"func": "print('B')",
			"functionname": "打印执行销售单"
		}];
		var typeBar = RECEIPT_FRONT_SYMBOL+RECEIPT_NEXT_SYMBOL+RECEIPT_EXPORT_SYMBOL;
		content = AddReceiptsToolBar(typeBar, tooldata);
		$("#toolbar").append(content); /*在ID=toolbar的标记后面添加content中的内容*/
		$(document).ready(function (){
			GetDetailTable();
			getPageMaxAndMin();
			loadRemote();
		});
		
		function frontpage() {
			if(id > MinPage) {
				var _url = RemoteLinkAddress + '/logistics/salesorder/pre.do?ID=' + id;
				getRemoteData(_url);
			} else {
				$.messager.alert("提示", "没有上张");
			}
		}

		function nextpage() {
			if(id < MaxPage) {
				var _url = RemoteLinkAddress + '/logistics/salesorder/next.do?ID=' + id;
				getRemoteData(_url);
			} else {
				$.messager.alert(" 提示", "没有下张");
			}
		}
		function getPageMaxAndMin() {
			var _url = RemoteLinkAddress + "/logistics/salesorder/getmaxminid.do";
			$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
				type: "get",
				url: _url,
				dataType: "json", //服务器返回的数据类型
				success: function(result) {
					if(result != null) {
						MaxPage = result.MAXID;
						MinPage = result.MINID;
					}
				}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}

		function print(type) {
			if(type == "A") {
				var pLocation = "SalesOrderAPrint.html?id=" + originalid;
			}
			if(type == "B") {
				var pLocation = "SalesOrderPrint.html?TYPE=B;" + id;
			}
			window.open(pLocation); /*打开pLocation中的链接html文档*/
		}


		function getRemoteData(_url) //统一获取远程的数据
		{
			$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
				type: "get",
				url: _url,
				dataType: "json", //服务器返回的数据类型
				success: function(result) {
					if(result != null) {
						currPageData = result;
						originalid = result.ORIGINALORDER_ID;
						id = result.ID;
						customerid = result.CUSTOMER_ID;
						var _data = result.rows; //将获取到的数据中字头为rows的数据赋值给_data
						$('#tt').datagrid('loadData', _data); //调用easyui的loadData方法，将数据写入id为tt的datagrid中
						CalSum();
						getFormData(result);
					}

				}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}
		//////////
		function loadRemote() { //载入服务器上的数据，用于修改以及查看更多的时候调用，根据id是否等于-1来判断
			var _url = RemoteLinkAddress + '/logistics/salesorder/findbyid.do?ID=' + id;
			getRemoteData(_url);
		}

		$('#input_sum').textbox({
			onChange: function(value) {
				var _trim = $.trim(value);
				var s = changeMoneyToChinese(_trim);
				$('#span_sum').html(s);
			}
		});

		function GetDetailTable() { //构造datagrid中的数据
			$('#tt').datagrid({
				height: 350,
				width: '100%',
				title: '',
				collapsible: true, //是否折叠：是
				singleSelect: true, //是否单选：是
				fitColumns: true, //自动调整列：是
				autoSave: true, //自动保存：是
				columns: [
					[{
						field: 'INTERNAL_NAME',
						title: '内部商品名',
						width: '20%',
						align: 'center',
					}, {
						field: 'INTERNAL_TYPE',
						title: '内部商品类型',
						width: '20%',
						align: 'center',
					}, 
					{
						field: 'UNIT_NAME',
						title: '单位',
						width: '16%',
						align: 'center',
					}, {
						field: 'UNIT_PRICE',
						title: '单价',
						width: '15%',
						align: 'center',
						formatter: function(value, row, index) {
							if(value) {
								return "￥" + value + "元";
							}
						}
					}, {
						field: 'AMOUNT',
						title: '数量',
						width: '15%',
						align: 'center',
						formatter: function(value, row, index) {
							if(value) {
								return value;
							}
						}
					}, {
						field: 'SUM',
						title: '总价',
						width: '15%',
						align: 'center',
						formatter: function(value, row, index) {
							if(value) {
								return "￥" + value + "元";
							}
						}
					}]
				]
			});
		}

		function CalSum() {
			var _num = 0;
			var dataGridRows = $("#tt").datagrid("getRows");
			for(var i = 0; i < dataGridRows.length; i++) {
				_num += parseFloat(dataGridRows[i].SUM);
			}
			var num = changeMoneyToChinese(_num);
			$("#dx").val(num);
			$("input[name='number']").val(_num.toFixed(2));
		}
		
		function exportExcel() {
			if(id === AddFlag) {
				$.messager.alert("警告", "该订单为新增订单，无法导出Excel！");
				return;
			}
			$.messager.confirm("提示", "确认导出Excel表格吗？", function(r) {
				if(r) {
					$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
						type: "get",
						dataType: "json", //服务器返回的数据类型
						url: RemoteLinkAddress + "/logistics/salesorder/excelorder.do",
						data: {
							"ID": currPageData.ID
						},
						success: function(result) {
							window.location.href = result.path;
						}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
						error: function(xhr, status, error) {
							$.messager.alert("错误", "请求失败!");
						}
					});
				}
			});
		}
	</script>

</html>